﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OrganizationName.CodeGeneration;

namespace OrganizationName.Factory
{
    public abstract class GenericMaterial : CodeProvider, ICodeProvider
    {
        public virtual string Base { get; set; }
        public virtual string Name { get; set; }
        public virtual string Impl { get; set; }

        public abstract System.Type GetAbstractType(ICodeContext codeContext);
        public abstract System.Type GetConcreteType(ICodeContext codeContext);

        public virtual string ContextKey
        {
            get
            {
                if (string.IsNullOrEmpty(Name))
                {
                    return null;
                }
                GenericMaterial parentMaterial = Parent as GenericMaterial;
                if (parentMaterial == null)
                {
                    return Name;
                }
                string parentContextKey = parentMaterial.ContextKey;
                if (string.IsNullOrEmpty(parentContextKey))
                {
                    return null;
                }
                return string.Format("{0}.{1}", parentContextKey, Name);
            }
        }

        public override string ToString()
        {
            string contextKey = ContextKey;
            return string.Format("{0} ({1})", GetType().Name, string.IsNullOrEmpty(contextKey) ? "?" : contextKey);
        }
    }
}
